#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
File: demo.py
Author: StellaJL
Date: 2025-09-16 14:56:50
Version：1.0.0
Description: 基础爬虫引擎使用示例
"""



import asyncio
from parseData import parser_custom_data
from saveData.sqliteSave import SqliteSaver
from engine.base_engine import BaseEngine

async def movieBase():
    """
    获取电影基础信息
    """
    # 定义起始URL列表
    start_urls = [
        'https://www.1905.com/mdb/film/list/o0d0p1.html'
    ]
    
    # 创建SQLite保存器实例
    sqlite_saver = SqliteSaver()
    
    # 检查SQLite是否启用
    if not sqlite_saver.is_enabled():
        print("SQLite未启用，请检查配置文件")
        return
    
    # 创建保存函数（绑定表名和索引字段）
    async def movie_save_func(data, url):
        await sqlite_saver.save(data, url, 'movies', 'title')
    
    # 创建并启动爬虫引擎
    engine = BaseEngine(
        start_urls=start_urls,
        parse_func=parser_custom_data,
        save_func=movie_save_func
    )
    
    # 启动爬虫
    await engine.start()

if __name__ == '__main__':
    asyncio.run(movieBase())
